from direct.gui.DirectGui import *
from pandac.PandaModules import TransparencyAttrib
import cfg

class GUI(object):
    """displays health and selected weapon on the screen"""

    def __init__(self):
        self.healthLbl = DirectWaitBar(text = "100",
                                   value = 100,
                                   pos = (-.9, 0, .65),
                                   scale = (.3,1,.4),
                                   textMayChange = 1,
                                   frameColor = (0, 0, 0, 0))

        self.enemyLbl = DirectWaitBar(text = "Enemy Name",
                                      value = 100,
                                      pos = (0,0,-.9))
        taskMgr.add(self.update, "gui update")
        self.selection = OnscreenImage("../textures/selector.png", scale = (.09,.09,.09), pos = (-1.1, 0, .8))
        self.weaponicons = [OnscreenImage("../textures/laser_icon.png", scale = (.1,.1,.1), pos = (-1.1, 0, .8)),
                            OnscreenImage("../textures/plasma_icon.png", scale = (.1,.1,.1), pos = (-.9, 0, .8)),
                            OnscreenImage("../textures/acid_icon.png", scale = (.1,.1,.1), pos = (-.7, 0, .8))]
                            
        for i in range(3):
            self.weaponicons[i].setTransparency(TransparencyAttrib.MAlpha)

    def update(self, task):
        self.healthLbl["text"] = "%s%%"%(cfg.player.health)
        self.healthLbl["value"] = cfg.player.health
        self.enemyLbl["text"] = "%s"%(cfg.enemy.name)
        if cfg.enemy.name == "Squidward":
            self.enemyLbl["value"] = cfg.enemy.health * 1.5
        elif cfg.enemy.name == "Annoying":
            self.enemyLbl["value"] = cfg.enemy.health * 2
        else:
            self.enemyLbl["value"] = cfg.enemy.health
        if cfg.player.firingmode == 0:
            self.selection.setPos(-1.1,0,.8)
        elif cfg.player.firingmode == 1:
            self.selection.setPos(-.9,0,.8)
        else:
            self.selection.setPos(-.7,0,.8)
        return task.cont